<template>
  <div id="app">
    <div id="main" style="width: 600px;height:400px;"></div>
  </div>
</template>
<script>
  export default {
    name: "app",
    methods: {
      drawChart() {
// 基于准备好的dom，初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById("main"));
// 指定图表的配置项和数据
        this.getRequest("/sales").then((data)=>{
          // console.log(data.data)
          var sale =data.data;
          var saleName= [];
          var saleCount= [];

          for (var i = 0 ;i<sale.length;i++){
            saleName[i] = sale[i].name;
            saleCount[i] = sale[i].count;
          }

          console.log(saleName)
          myChart.setOption({
            title:{
              text: "ECharts 入门示例"
            },
            tooltip: {},
            legend: {
              data: ["销量"]
            },
            xAxis: {
              data: saleName,
              name:'产品'
            },
            yAxis: {},
            series:[{
              name:'销量',
              type:'line',
              data:saleCount
            }]
          });
        });
      }
    },
    mounted() {
      this.drawChart();
    }
  };
</script>
